package cn.cqie.attendance.manager.service.impl;

import cn.cqie.attendance.common.util.Page;
import cn.cqie.attendance.common.util.PageBean;
import cn.cqie.attendance.manager.dao.AdminScoreDao;
import cn.cqie.attendance.manager.pojo.*;
import cn.cqie.attendance.manager.service.AdminGroupService;
import cn.cqie.attendance.manager.service.AdminScoreService;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author king james
 * @create 2021-07-07-{TIME}
 */
@Service
public class AdminScoreServiceImpI implements AdminScoreService {
    @Autowired
    private AdminScoreDao scoreDao;

    /**
     * 组合查询学生综合得分详情
     * @param courseName 课程名
     * @param groupName 小组名
     * @param pageSize 每一页的数量
     * @param pageNum 当前页
     * @return
     */
    @Override
    public PageBean<AdminStudentScore> queryAllStudentScoreInfo(String courseName, String groupName, Integer pageSize, Integer pageNum) {

        if (pageNum == null || pageSize == null){
            pageNum = 1;
            pageSize = 10;
        }
        PageHelper.startPage(pageNum,pageSize);

        AdminStudentScore studentScore = new AdminStudentScore();

        studentScore.setCourseName(courseName);
        studentScore.setGroupName(groupName);

        List<AdminStudentScore> list  = scoreDao.queryAllStudentScoreInfo(studentScore);
        int total = list.size();

        if (null == list || total == 0) {
            return new PageBean<>(201,"error",list);
        }
        return new PageBean<>(200,"success",list);
        }

    /**
     * 根据id查询学生得分详情
     * @param stuId 学id
     * @return
     */
    public Page<AdminStudentScore> queryStudentScoreById(Integer stuId,Integer courseId) {
        List<AdminStudentScore> list  = scoreDao.queryStudentScoreById(stuId,courseId);
        int total = list.size();
        if (null == list || total== 0) {
            return Page.INFOERROR;
        }
        return new Page<>(200, "Success",0,0, total, list);
    }

    /**
     * 根据学生id查询学生的所有作业完成情况
     * @param stuId 学生id
     * @param pageSize 每一页数量
     * @param pageNum 当前页
     * @return
     */

    @Override
    public PageBean<AdminStudentHomework> queryAllStudentHomeworkInfoById(Integer stuId,Integer courseId, Integer pageSize, Integer pageNum) {
        if (pageNum == null || pageSize == null){
            pageNum = 1;
            pageSize = 10;
        }
        PageHelper.startPage(pageNum,pageSize);
        List<AdminStudentHomework> list  = scoreDao.queryAllStudentHomeworkInfoById(stuId,courseId);
        int total = list.size();

        if (null == list || total == 0) {
            return new PageBean<>(201,"error",list);
        }
        return new PageBean<>(200,"success",list);

    }

    /**
     * 根据id查询学生一次作业详情
     * @param homeworkId 作业id
     * @return
     */
    @Override
    public Page<AdminStudentHomework> queryStudentHomeworkById(Integer homeworkId) {
        List<AdminStudentHomework> list  = scoreDao.queryStudentHomeworkInfoById(homeworkId);
        int total = list.size();
        if (null == list || total== 0) {
            return Page.INFOERROR;
        }
        return new Page<>(200, "Success",0,0, total, list);
    }

    /**
     * 组合查询所有小组得分列表
     * @param courseName 课程名
     * @param groupName 小组名
     * @param pageSize 每页数量
     * @param pageNum 当前页
     * @return
     */
    @Override
    public PageBean<AdminGroupScore> queryAllGroupScoreInfo(String courseName, String groupName, Integer pageSize, Integer pageNum) {
        if (pageNum == null || pageSize == null){
            pageNum = 1;
            pageSize = 10;
        }
        PageHelper.startPage(pageNum,pageSize);
        AdminGroupScore groupScore = new AdminGroupScore();
        groupScore.setCourseName(courseName);
        groupScore.setGroupName(groupName);
        List<AdminGroupScore> list  = scoreDao.queryAllGroupScoreInfo(groupScore);
        int total = list.size();
        if (null == list || total == 0) {
            return new PageBean<>(201,"error",list);
        }
        return new PageBean<>(200,"success",list);
    }



    /**
     * 根据id查询小组得分详情
     * @param groupId 小组id
     * @return
     */
    @Override
    public Page<AdminGroupScore> queryGroupScoreById(Integer groupId,Integer groupCourseId) {
        List<AdminGroupScore> list  = scoreDao.queryGroupScoreInfoById(groupId,groupCourseId);
        int total = list.size();
        if (null == list || total== 0) {
            return Page.INFOERROR;
        }
        return new Page<>(200, "Success",0,0, total, list);
    }

    /**
     * 根据小组查询小组作业完成情况
     * @param groupId 小组id
     * @param groupCourseId 课程id
     * @param pageSize 每页数量
     * @param pageNum 当前页
     * @return
     */
    @Override
    public PageBean<AdminGroupHomework> queryAllGroupHomeworkInfoById(Integer groupId,Integer groupCourseId, Integer pageSize, Integer pageNum) {
        if (pageNum == null || pageSize == null){
            pageNum = 1;
            pageSize = 10;
        }
        PageHelper.startPage(pageNum,pageSize);
        List<AdminGroupHomework> list  = scoreDao.queryAllGroupHomeworkInfoById(groupId,groupCourseId);
        int total = list.size();
        if (null == list || total == 0) {
            return new PageBean<>(201,"error",list);
        }
        return new PageBean<>(200,"success",list);
    }

    @Override
    public Page<AdminGroupHomework> queryGroupHomeworkInfoById(Integer homeworkId) {
        List<AdminGroupHomework> list  = scoreDao.queryGroupHomeworkInfoById(homeworkId);
        int total = list.size();
        if (null == list || total== 0) {
            return Page.INFOERROR;
        }
        return new Page<>(200, "Success",0,0, total, list);
    }
}
